package edu.avans.hartigehap.domain;

//the actual Iterator, implementing the Iterator Interface we defined.
public class IngredientIterator implements CustomIterator 
{
	Ingredient[] ingredients;
	int position = 0;
	
	public IngredientIterator(Ingredient[] ingredients)
	{
		this.ingredients = ingredients;
	}
	
	@Override
	public Object next() {
		//get the item @ position x in the array of items
		Ingredient ingredient = ingredients[position];
		//position ++, to go to the next item
		position = position +1;
		//return the object
		return ingredient;
	}
	
	
	@Override
	public boolean hasNext() {
		//check if the number of items is smaller then the position AND if the next item exists(position set @ next();)
		
		if(position >= ingredients.length || ingredients[position] == null)
		{
			//there is no next object or the array is too small
			return false;
		}
		//there is a next object
		return true;
	}

	@Override
	public Object currentItem() {
		//get the item @ position x in the array of items
		Ingredient ingredient = ingredients[position];

		//return the object
		return ingredient;
	}

	@Override
	public Object first() {
		// First in the list, is item 0
		Ingredient ingredient = ingredients[0];
		
		//return the object
		return ingredient;
	}

	@Override
	public boolean isDone() {
		
		// If the position is greater than the last or just as large as the last, we are at the end (-:
		
		if(position >= ingredients.length )
			return false;
		else
			return true;
	}

	@Override
	public boolean remove() {
		// TODO Auto-generated method stub
		return false;
	}


	
}

